package com.example.demo02.listener;

import cn.hutool.core.date.DateUtil;
import com.example.demo02.dto.ValueChangeDTO;
import com.example.demo02.listener.event.BaseEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Objects;

@Component
public class ValueChangeListener {
//    @EventListener(condition = "#event.success")
    @Async("taskExecutor")
    public void onApplicationEvent(BaseEvent<ValueChangeDTO> event){
        ValueChangeDTO data = event.getData();
        if(Objects.isNull(data)){
            return;
        }
        switch (data.getKeyName()){
            case on_line:
                if(!Objects.equals(data.getNewValue(),data.getOldValue())
                && Objects.equals(data.getNewValue(),Boolean.TRUE.toString())){
                    System.out.println("平台上线了昂----"+ DateUtil.formatDateTime(new Date()));
                }
                break;
            default:
                break;
        }
    }
}
